<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>background-size: cover vs contain</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      padding: 20px;
      margin: 0;
    }
    
    .container {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      margin-top: 20px;
    }
    
    .box {
      width: 300px;
      height: 200px;
      border: 1px solid #ddd;
      margin-bottom: 20px;
      color: white;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: center;
      text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
      background-color: #f0f0f0;
    }
    
    /* cover 示例 */
    .cover {
      background-image: url('https://picsum.photos/seed/cover/800/400');
      background-size: cover;
      background-position: center;
    }
    
    /* contain 示例 */
    .contain {
      background-image: url('https://picsum.photos/seed/contain/800/400');
      background-size: contain;
      background-repeat: no-repeat;
      background-position: center;
    }
    
    /* 不同比例的容器 */
    .tall {
      height: 300px;
    }
    
    .wide {
      width: 400px;
    }
    
    /* 说明文字 */
    .caption {
      margin-top: 10px;
      text-align: center;
      color: #666;
    }
  </style>
</head>
<body>
  <h1>background-size: cover vs contain</h1>
  
  <div class="container">
    <!-- 标准比例容器 -->
    <div>
      <div class="box cover">cover</div>
      <div class="caption">标准容器：cover（覆盖但可能裁剪）</div>
    </div>
    
    <div>
      <div class="box contain">contain</div>
      <div class="caption">标准容器：contain（完整显示但可能留白）</div>
    </div>
    
    <!-- 高容器 -->
    <div>
      <div class="box cover tall">cover</div>
      <div class="caption">高容器：cover（横向裁剪）</div>
    </div>
    
    <div>
      <div class="box contain tall">contain</div>
      <div class="caption">高容器：contain（上下留白）</div>
    </div>
    
    <!-- 宽容器 -->
    <div>
      <div class="box cover wide">cover</div>
      <div class="caption">宽容器：cover（纵向裁剪）</div>
    </div>
    
    <div>
      <div class="box contain wide">contain</div>
      <div class="caption">宽容器：contain（左右留白）</div>
    </div>
  </div>
</body>
</html>
